package com.devops.admin.graphql;

import com.devops.admin.service.DOSK8sDeploymentService;
import com.devops.admin.vo.DOSDeploymentVo;
import com.devops.common.annotation.DOSLog;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @ClassName DOSK8sDeploymentDataFetcher
 * @Description TODO
 * @Author heyabo
 * @Date 2022/8/3 17:44
 * @Version 1.0
 **/
@DgsComponent
public class DOSK8sDeploymentDataFetcher {

    @Autowired
    private DOSK8sDeploymentService dosk8sDeploymentService;

    /**
     * @Author heyabo
     * @Description 对deployment进行扩容
     * @Date 11:19 2022/5/20
     * @Param [releaseId, scale, deploymentName]
     * @return boolean
     **/
    @DgsMutation
    @DOSLog(description = "对deployment进行扩容")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public boolean scaleDeployment(@InputArgument DOSDeploymentVo deployment){
        return dosk8sDeploymentService.scaleDeployment(deployment.getId(),deployment.getScale(), deployment.getDeploymentName(), deployment.getType());
    }

    /**
     * @Author heyabo
     * @Description 重启Deployment
     * @Date 11:27 2022/5/20
     * @Param [releaseId, scale, deploymentName]
     * @return boolean
     **/
    @DgsMutation
    @DOSLog(description = "重启Deployment")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public boolean restartDeployment(@InputArgument DOSDeploymentVo deployment){
        return dosk8sDeploymentService.restartDeployment(deployment.getId(),deployment.getDeploymentName(),deployment.getType());
    }

    /**
     * @Author heyabo
     * @Description 删除deployment
     * @Date 13:56 2022/5/20
     * @Param [releaseId, deploymentName]
     * @return boolean
     **/
    @DgsMutation
    @DOSLog(description = "删除deployment")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public boolean deleteDeployment(@InputArgument DOSDeploymentVo deployment){
        return dosk8sDeploymentService.deleteDeployment(deployment.getId(),deployment.getDeploymentName(),deployment.getType());
    }

    /**
     * @Author heyabo
     * @Description 获取Deployment
     * @Date 08:45 2022/5/19
     * @Param [releaseId]
     * @return java.util.List<com.devops.admin.po.DOSK8sDeployment>
     **/
//    @DgsQuery
//    @DOSLog(description = "获取k8s Deployment 详情")
//    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
//    public List<DOSK8sDeployment> getK8sDeploymentInfo(@InputArgument DOSDeploymentVo deployment) throws IOException {
//        DOSNamespaceChart dosNamespaceChart = dosk8sDeploymentService.dealDbDeployment(deployment);
//        return dosk8sDeploymentService.getK8sDeploymentInfo(dosNamespaceChart);
//    }
}
